/**
 * @author:稀饭
 * @time:下午7:17:40
 * @filename:Work.java
 */
package work;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import com.sun.javafx.binding.StringFormatter;

import config.Config;
import util.FileOperationUtil;
import util.FileSender;
import util.GetFilesInDir;

public class Work {
	private final String foldPath = "pinfo\\";
	/**
	 * @描述：
	 * 
	 * @时间：下午7:17:40
	 * @开发者：稀饭 @测试：通過
	 * @param
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Work().work();
	}
	/**
	 *  @描述：
	 *  @时间：下午5:15:48
	 *  @开发者：稀饭
	 *  @测试：通过
	 *  @param
	 */
	public void work() {

		ArrayList<String> list = new GetFilesInDir(Config.filePath).work();
		FileOperationUtil.createHtml(foldPath, Config.fileName, "##该文件放置的是文件的上传信息，勿删##\n");
		HashMap<String, String> map = FileOperationUtil.readLineContent("pinfo\\", Config.fileName);
		boolean renew = false;
		for (int i = 0; i < list.size(); i++) {
			FileSender fileSender = new FileSender(Config.serverPath, Config.port, list.get(i), map);
			long fileLen = fileSender.work();
			if (fileLen != 0)
				renew = true;
		}
		if (renew) {
			FileOperationUtil.createHtmlDelete(foldPath, Config.fileName, "##该文件放置的是文件的上传信息，勿删##\n");
			Set<String> set = map.keySet();
			Iterator<String> iterator = set.iterator();
			while (iterator.hasNext()) {
				String key = iterator.next();
				String value = map.get(key);
				FileOperationUtil.appendFile(foldPath, Config.fileName, key+"?"+value+"\n");
			}
		}
	}
}
